perm filename NUMRIC.SAI[PIC,HE]1 blob sn#421660 filedate 1979-02-24 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	entry  numric
C00006 ENDMK
C⊗;
entry  numric;
begin

  require  "<nevatia>abbrev.sai"  source!file;

  comment
  This file contains a set of procedures useful for numerical
  computations. Part of the reason that these have been written
  is that I could not have confidence in the routines supplied  
  by SAIL.;

  define  infinity = "65535";
  internal  simple  boolean  procedure  even(integer  n);
  begin
    if  n mod 2 = 0  then  return(true)
                     else  return(false);
  end;  " even "

  internal  simple  real  procedure  myatan(real  num, den);
  begin
  comment
  arctan(.)  ;
  real  angle;
    if  den = 0  then  
    begin
      if  num = 0  then  angle ← 0
                   else  angle ← 90.0;
    end  else
    angle ← atan(Abs(num/den)) * (180/pi);
    if  num geq 0  then
    begin
      if  den < 0  then  angle ← 180.0 - angle
    end  else
    if  den > 0  then  angle ← 360.0 - angle
                 else  angle ← 180.0 + angle;
    return(angle);
  end;  "myatan"

  internal  simple  integer  procedure  modd(integer n, modulo);
  begin
  comment
  The modulo function provided by SAIL is not the same as the
  mathematical one. Hence this procedure.;
    if  n < 0  then
    do  begin
      n ← n + modulo;
    end  until  n geq 0;
    return(n mod modulo);
  end;  "modd"

  internal  simple  real  procedure  tand(real  deg);
  begin
  comment
  This is not available in SAIL.;
    if  cosd(deg) = 0.0  then  return(1.0*infinity)
                         else  return(sind(1.0*deg)/cosd(1.0*deg));
  end;  "tand"

end